package com.hdd.art.biz.show.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdd.art.biz.show.entity.OpenScreen;
import com.hdd.art.biz.show.mapper.OpenScreenMapper;
import com.hdd.art.biz.show.service.OpenScreenService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 开屏画展 服务实现类
 * </p>
 *
 * @author fang
 * @since 2021-06-27
 */
@Service
public class OpenScreenServiceImpl extends ServiceImpl<OpenScreenMapper, OpenScreen> implements OpenScreenService {

    @Override
    public List<OpenScreen> findOpenScreenByArtId(String artId) {
        QueryWrapper<OpenScreen> wrapper = new QueryWrapper<>();
        wrapper.eq("art_Id",artId);
        wrapper.orderByDesc("is_use");
        return  baseMapper.selectList(wrapper);
    }

    @Override
    public OpenScreen defaultOpenScreenByArtId(String artId) {
        QueryWrapper<OpenScreen> wrapper = new QueryWrapper<>();
         wrapper.eq("art_Id",artId);
         wrapper.eq("is_use","T");
         wrapper.last("limit 1");
        return baseMapper.selectOne(wrapper);
    }


    @Override
    public void insert(OpenScreen openScreen) {
        baseMapper.insert(openScreen);
    }

    @Override
    public void delete(Integer id) {
        baseMapper.deleteById(id);
    }


    @Override
    public void setDefaultOpenScreen(Integer id) {
       QueryWrapper<OpenScreen> wrapper = new QueryWrapper<>();
        wrapper.ne("id",id);
        OpenScreen openScreen = new OpenScreen();
        openScreen.setId(id);
        openScreen.setIsUse("F");
        baseMapper.update(openScreen,wrapper);
        wrapper = new QueryWrapper<>();
        wrapper.eq("id",id);
        openScreen.setIsUse("T");
        baseMapper.update(openScreen,wrapper);
    }
}
